package com.metaera.app.controller;

import android.graphics.Color;
import android.graphics.drawable.Drawable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.controller.core.IPaginationPresenter;
import com.metaera.app.controller.core.SimplePaginationPresenter;
import com.metaera.app.controller.view.core.IPaginationView;
import com.metaera.app.data.DataRepository;
import com.metaera.app.data.model.ArticleListResponse;
import com.metaera.app.data.model.BasicListResponse;
import com.metaera.app.data.model.HotColumnResponse;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.ui.adapters.HomeFollowNewsAdapter;
import com.metaera.app.ui.adapters.HotColumnAdapter;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import io.reactivex.Observable;

public class PaginationContractFactory {

    /**
     * 关注者的文章
     */
    public PaginationContract<ArticleListResponse> followArticle() {

        return new PaginationContract<ArticleListResponse>() {

            @Override
            protected BaseQuickAdapter<ArticleListResponse, BaseViewHolder> createAdapter(RecyclerView recyclerView) {
                return new HomeFollowNewsAdapter();
            }

            @Override
            protected IPaginationPresenter<IPaginationView<ArticleListResponse>, ArticleListResponse> createPresenter() {
                return new SimplePaginationPresenter<ArticleListResponse>() {

                    @Override
                    protected Observable<BasicListResponse<ArticleListResponse>> execute() {
                        return DataRepository.getInstance().getFollowLists(mPage, ApiParam.PAGE_SIZE);
                    }

                };
            }
        };
    }


    /**
     * 热门专栏
     */
    public PaginationContract<HotColumnResponse> hotColumn() {

        return new PaginationContract<HotColumnResponse>() {

            @Override
            protected BaseQuickAdapter<HotColumnResponse, BaseViewHolder> createAdapter(RecyclerView recyclerView) {
                DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
                Drawable drawable = ContextCompat.getDrawable(recyclerView.getContext(), R.drawable.shape_item_divider);
                dividerItemDecoration.setDrawable(drawable);
                recyclerView.addItemDecoration(dividerItemDecoration);
                recyclerView.setBackgroundColor(Color.WHITE);
                return new HotColumnAdapter();
            }

            @Override
            protected IPaginationPresenter<IPaginationView<HotColumnResponse>, HotColumnResponse> createPresenter() {
                return new SimplePaginationPresenter<HotColumnResponse>() {

                    @Override
                    protected Observable<BasicListResponse<HotColumnResponse>> execute() {
                        return DataRepository.getInstance().getPopularColumn(ApiParam.AUTHOR_TYPE, mPage, ApiParam.PAGE_SIZE);
                    }

                };
            }
        };
    }



}
